package com.itheima.exceptionDemo;

import java.util.Scanner;

public class ExceptionDemo04 {
    public static void main(String[] args) {
        try {
            input();
        } catch (MyException e) {
            System.out.println(e.getMessage());//您输入的值不符合规范！
        }
    }

    private static void input() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个1-100之间的值：");
        String value = sc.nextLine();
        int i = Integer.parseInt(value);
        if (i<1 || i>100){
            throw new MyException("您输入的值不符合规范！");//向上抛出异常
        }else {
            System.out.println(i);
        }
    }
}


//自定义异常
class MyException extends RuntimeException{
    public MyException() {
    }

    public MyException(String message) {
        super(message);
    }
}